<template>
	<view class="bbscommentpost">

		<view class="comment_textarea_box">
			<textarea class="comment_textarea" v-model="content" placeholder="添加评论..." :show-confirm-bar="false"
				maxlength="500" :disable-default-padding="true"></textarea>
			<view class="display_flex" style="justify-content: flex-end;">
				<view class="f-12">{{content.length}}/500</view>
				<view class="post_btn" @click="submitBbsComment">发布</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		submitBbsComment,
		checkText
	} from '@/api/motortime.js';
	let app = getApp()
	export default {
		data() {
			return {
				card_id: '',
				content: '',
				rid: '',
				isSubmit: true,
			};
		},
		onShow() {

		},
		onLoad(options) {
			console.log(options)
			this.card_id = options.card_id
			this.rid = options.rid ? options.rid : ''
			var params = {
				event_code: '评论',
				path: 'pages/bbs/bbscommentpost',
				event_id: this.card_id,
				title: '',
				source_page: '',
				value: '',
			}
		},
		methods: {
			submitBbsComment() {
				var that = this
				var params = {
					event_code: '评论',
					path: 'pages/bbs/bbscommentpost',
					event_id: that.card_id,
					title: '',
					source_page: '评论-发布',
					value: '',
				}
				app.BurialPoint(params)
				if (that.isSubmit) {
					that.isSubmit = false
					if (that.content == '') {
						uni.showToast({
							title: '请输入评论内容',
							mask: true,
							icon: 'none',
							duration: 1500
						})
						that.isSubmit = true
						return false;
					}
					checkText({
						content: that.content,
					}).then(res => {
						if (res.state == 1) {
							submitBbsComment({
								card_id: that.card_id,
								rid: that.rid,
								content: that.content,
							}).then(res => {
								if (res.state == 1) {
									uni.showToast({
										title: '评论成功',
										mask: true,
										icon: 'success',
										duration: 1500
									})
									uni.setStorage({
										key: 'onload',
										data: true,
									})
									setTimeout(function() {
										that.content = ''
										uni.navigateBack({
											delta: 1
										})
										that.isSubmit = true
									}, 1500)
									var params = {
										event_code: '评论',
										path: 'pages/bbs/bbscommentpost',
										event_id: that.card_id,
										title: '',
										source_page: '评论-成功',
										value: '',
									}
									app.BurialPoint(params)
								} else {
									that.isSubmit = true
									uni.showToast({
										title: res.error[0],
										mask: true,
										icon: 'none',
										duration: 1500
									})
								}
							})

						} else {
							that.isSubmit = true
							uni.showToast({
								title: res.error[0],
								mask: true,
								icon: 'none',
								duration: 1500
							});
						}
					})

				}

			}
		},
	}
</script>

<style lang="scss">
	.bbscommentpost {
		padding: 30rpx;

		.comment_textarea_box {
			padding-bottom: 30rpx;
			border-bottom: 2rpx solid #E9E9E9;

			.comment_textarea {
				width: 100%;
				height: 40vh;
				font-size: 26rpx;
				line-height: 40rpx;
			}

			.post_btn {
				color: #ffffff;
				font-size: 28rpx;
				margin-left: 30rpx;
				padding: 20rpx 50rpx;
				border-radius: 8rpx;
				background-color: #00A0DC;
			}
		}


	}
</style>